package com.bw.task.mvp.model;

import com.bw.task.api.Api;
import com.bw.task.bean.ImgBean;
import com.bw.task.bean.MoneyBean;
import com.bw.task.bean.PopupWindioBean;
import com.bw.task.bean.UserBean;
import com.bw.task.http.HttpRetrofit;
import com.bw.task.http.HttpRetrofit2;
import com.bw.task.mvp.contern.UserContent;
import com.google.gson.JsonObject;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class UserModel implements UserContent.mModel {

    @Override
    public void rquestreg(String name, String pass, Observer<UserBean> observer) {
//        String name = username.getText().toString().trim();
//        String pass = userpass.getText().toString().trim();
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("userName",name);
        jsonObject.addProperty("userPwd",pass);
        RequestBody body = RequestBody.create(MediaType.parse("*/*"), jsonObject.toString());
        HttpRetrofit.getHttpRetrofit().getRetrofit()
                .create(Api.class)
                .register("register/new?userName="+name+"&userPwd="+pass)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void rquestlog(String name, String pass, Observer<UserBean> observer) {
        HttpRetrofit.getHttpRetrofit().getRetrofit()
                .create(Api.class)
                .loginer("login/in?userName="+name+"&userPwd="+pass)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void requestimg(String path, Observer<ImgBean> observer) {
        HttpRetrofit2.getHttpRetrofit().getRetrofit()
                .create(Api.class)
                .get("vertical/category/4e4d610cdf714d2966000000/vertical?limit=30&adult=false&first=2&order=new")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);


    }

    @Override
    public void requestmoney(String id, String money, Observer<MoneyBean> observer) {
        //http://www.fenghongzhang.com:7777/recharge/user?id=1&money=10
        HttpRetrofit.getHttpRetrofit().getRetrofit()
                .create(Api.class)
                .money("recharge/user?id="+id+"&money="+money)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }


    //vertical/category/4e4d610cdf714d2966000000/vertical?limit=30&adult=false&first=2&order=new

    @Override
    public void destory() {

    }
}
